package edu.spangler.dang.FriendTracker;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.preference.PreferenceManager;
import android.util.Log;

/**
 * Receives intent broadcasts for when device boot has been completed.
 */

public class BootBroadcastReceiver extends BroadcastReceiver
{
    /**
     * This method is called when the BroadcastReceiver is receiving an Intent broadcast.
     * @param context The Context in which the receiver is running.
     * @param intent The intent being received.
     */
    
    @Override
    public void onReceive(Context context, Intent intent)
    {
        String userName = PreferenceManager.getDefaultSharedPreferences(context).getString(FriendTrackerControl.NamePreference, null);
        Log.d("FriendTracker", "Running service at boot for user " + userName);
        
        if (userName != null)
        {
            Intent serviceIntent = new Intent(context, FriendTracker.class);
            serviceIntent.putExtra(FriendTracker.ExtraUserName, userName);
            context.startService(serviceIntent);
        }
    }
}
